

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="@[toc] 参考资料 参考资料：视频资料 面向对象设计，Object Oriented Design，简称OOD。 在进行软件开发时，需要考虑项目的可维护性和可复用性，开发项目一般是由一个开发团队来维护，因此我们在编写代码时，应可能规范，防止项目出现越来越多的BUG。 一、单一职责原则 SRP 参考资料：查看文档 单一职责原则， Single Responsibility Principle 又">
<meta property="og:type" content="article">
<meta property="og:title" content="Java 笔记 面向对象的七大设计原则">
<meta property="og:url" content="http://example.com/2022/07/11/Java%20%E7%AC%94%E8%AE%B0%20%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E7%9A%84%E4%B8%83%E5%A4%A7%E8%AE%BE%E8%AE%A1%E5%8E%9F%E5%88%99/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="@[toc] 参考资料 参考资料：视频资料 面向对象设计，Object Oriented Design，简称OOD。 在进行软件开发时，需要考虑项目的可维护性和可复用性，开发项目一般是由一个开发团队来维护，因此我们在编写代码时，应可能规范，防止项目出现越来越多的BUG。 一、单一职责原则 SRP 参考资料：查看文档 单一职责原则， Single Responsibility Principle 又">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-07-11T13:03:33.000Z">
<meta property="article:modified_time" content="2022-08-22T15:45:13.703Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="Java">
<meta name="twitter:card" content="summary_large_image">
  
  
  
  <title>Java 笔记 面向对象的七大设计原则 - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Java 笔记 面向对象的七大设计原则"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-07-11 21:03" pubdate>
          2022年7月11日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          6.7k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          56 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Java 笔记 面向对象的七大设计原则</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <p>@[toc]</p>
<h1 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h1><hr>
<p>参考资料：<a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1u3411P7Na">视频资料</a></p>
<p>面向对象设计，Object Oriented Design，简称OOD。</p>
<p>在进行软件开发时，需要考虑项目的可维护性和可复用性，开发项目一般是由一个开发团队来维护，因此我们在编写代码时，应可能规范，防止项目出现越来越多的BUG。</p>
<h1 id="一、单一职责原则-SRP"><a href="#一、单一职责原则-SRP" class="headerlink" title="一、单一职责原则 SRP"></a>一、单一职责原则 SRP</h1><hr>
<p>参考资料：<a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E5%8D%95%E4%B8%80%E8%81%8C%E8%B4%A3%E5%8E%9F%E5%88%99/9456515">查看文档</a></p>
<p>单一职责原则， Single Responsibility Principle 又称单一功能原则，是最简单的面向对象设计原则，用于控制类的粒度大小。<br>出自《<a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E6%95%8F%E6%8D%B7%E8%BD%AF%E4%BB%B6%E5%BC%80%E5%8F%91%EF%BC%9A%E5%8E%9F%E5%88%99%E3%80%81%E6%A8%A1%E5%BC%8F%E4%B8%8E%E5%AE%9E%E8%B7%B5/2326384">敏捷软件开发：原则、模式与实践</a>》 Robert C. Martin</p>
<blockquote>
<p>一个对象应该只包含单一的职责，并且该职责被完整的封装在一个类中</p>
</blockquote>
<p><strong>例：用类描述人们的会做的事情</strong></p>
<ul>
<li><p>反例：违背 SRP 单一职责原则</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">People</span>&#123;<br>    <span class="hljs-comment">// 程序员: 敲代码</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">coding</span><span class="hljs-params">()</span>&#123;&#125;<br>    <span class="hljs-comment">// 飞行员: 驾驶飞机</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">pilot</span><span class="hljs-params">()</span>&#123;&#125;<br>&#125;<br></code></pre></td></tr></table></figure>
<p>类中出现了范围偏多的敲代码和驾驶飞机，实际上，生活中很少有人同时具备这两项技能，故根据 SRP 原则，上述的类应变更为：</p>
</li>
<li><p>正例：符合 SRP 原则</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 程序员</span><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">Programmer</span>&#123;<br>     <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">coding</span><span class="hljs-params">()</span>&#123;&#125;   <br>&#125;<br><br><span class="hljs-comment">// 飞行员</span><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">Piloter</span>&#123;<br>     <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">pilot</span><span class="hljs-params">()</span>&#123;&#125;   <br>&#125;<br></code></pre></td></tr></table></figure>
<p>总结：SRP 单一职责原则 要求在设计类的时候，里面的方法或属性是同一类的，颗粒度尽可能小的。</p>
</li>
</ul>
<h1 id="二、开闭原则-OCP"><a href="#二、开闭原则-OCP" class="headerlink" title="二、开闭原则 OCP"></a>二、开闭原则 OCP</h1><hr>
<p>参考资料：<a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E5%BC%80%E9%97%AD%E5%8E%9F%E5%88%99/2828775">查看文档</a><br>开闭原则，Open Close Principle，OCP 原则规定软件中的对象（类、模块、函数等）应对扩展开放，对修改关闭。<br>出自：《面向对象软件构造》</p>
<blockquote>
<p>软件对扩展（提供方）开放，对修改（调用方）关闭</p>
</blockquote>
<p><strong>正例：用类描述不同编程语言领域的程序员</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">abstract</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Programmer</span>&#123;<br>     <span class="hljs-keyword">public</span> <span class="hljs-keyword">abstract</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">Codding</span><span class="hljs-params">()</span>; <br>&#125;<br><br><span class="hljs-comment">// Java程序员</span><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">JavaProgrammer</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">Programmer</span>&#123;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">coding</span><span class="hljs-params">()</span>&#123;&#125;<br>&#125;<br><br><span class="hljs-comment">// Python 程序员</span><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">PythonProgrammer</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">Programmer</span>&#123;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">coding</span><span class="hljs-params">()</span>&#123;&#125;<br>&#125;<br><br><span class="hljs-comment">// C++语言程序员</span><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">CppProgrammer</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">Programmer</span>&#123;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">coding</span><span class="hljs-params">()</span>&#123;&#125;<br>&#125;<br></code></pre></td></tr></table></figure>
<p>通过提供一个 Programmer 抽象类，定义出编程的抽象行为，这样给其他具体类型的程序员来实现，这样就可以根据不同的业务进行灵活扩展，具有更好的扩展性。除了抽象类，更多的则是使用接口和接口实现类来遵循OCP原则</p>
<h1 id="三、里氏替换原则-LSP"><a href="#三、里氏替换原则-LSP" class="headerlink" title="三、里氏替换原则 LSP"></a>三、里氏替换原则 LSP</h1><hr>
<p>参考资料：<a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E9%87%8C%E6%B0%8F%E6%9B%BF%E6%8D%A2%E5%8E%9F%E5%88%99/3744239">查看文档</a></p>
<p>里氏替换原则，Liskov Substitution Principle，LSP 原则是对子类型的特别定义。</p>
<p>出自：演讲《数据的抽象与层次》 Barbara Liskov </p>
<blockquote>
<p>所有引用基类的地方必须能透明的使用其子类的对象</p>
</blockquote>
<p>简单来说，子类可以扩展父类的功能，但不能改变父类原有的功能：</p>
<ol>
<li>子类可以实现父类的抽象方法，但不能覆盖父类原有的功能</li>
<li>子类可以增加自己持有的方法</li>
<li>子类重载父类方法时，方法的前置条件（即方法的入参）要比父类的该方法入参更宽松</li>
<li>子类实现父类方法时，（重写&#x2F;重载或实现抽象方法），方法的后置条件（即方法的输出&#x2F;返回值）要比父类更严格或与父类一样</li>
</ol>
<p><strong>例： 描述一个Java程序员会做的事情</strong><br>反例：违背 LSP 原则</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">abstract</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Programmer</span>&#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">coding</span><span class="hljs-params">()</span>&#123;&#125;  <br>&#125;<br><br><span class="hljs-comment">// 描述会经常运动的Java程序员</span><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">JavaProgrammer</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">Programmer</span>&#123;   <br>    <span class="hljs-comment">// 违背 LSP 原则，重写了父类非抽象的方法。</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">codding</span><span class="hljs-params">()</span>&#123;&#125;<br>    <span class="hljs-comment">// 拓展功能: 做运动</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">doSport</span><span class="hljs-params">()</span>&#123;&#125;<br>&#125;<br></code></pre></td></tr></table></figure>
<p>正确例子：遵循 以上三种原则</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">abstract</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Programmer</span>&#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">abstract</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">coding</span><span class="hljs-params">()</span>&#123;&#125;  <br>    <span class="hljs-comment">// 程序员都需要休息</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">sleep</span><span class="hljs-params">()</span>&#123;&#125;<br>&#125;<br><br><span class="hljs-comment">// 描述会经常运动的Java程序员</span><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">JavaProgrammer</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">Programmer</span>&#123;<br>    <br>    <span class="hljs-comment">// public void sleep() , 遵循 LSP原则，不覆盖原有的功能, 除非sleep()为抽象的方法</span><br>    <span class="hljs-comment">// 重写父类方法</span><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">codding</span><span class="hljs-params">()</span>&#123;&#125;<br>    <span class="hljs-comment">// 拓展功能: 做运动</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">doSport</span><span class="hljs-params">()</span>&#123;&#125;<br>&#125;<br></code></pre></td></tr></table></figure>
<h1 id="四、依赖倒转原则-DIP"><a href="#四、依赖倒转原则-DIP" class="headerlink" title="四、依赖倒转原则 DIP"></a>四、依赖倒转原则 DIP</h1><hr>
<p>依赖倒转原则，Dependence Inversion Procinple，DIP原则指出程序要依赖抽象接口，不要依赖于具体实现。这在Spring框架中得到了广泛运用。</p>
<blockquote>
<p>高层模块不应依赖于底层模块。抽象不应依赖于细节，细节应依赖于抽象。</p>
</blockquote>
<p>以 JavaEE开发中，传统的MVC架构为例：<br>反例：违背了 DIP 原则 </p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Solution</span>&#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span>&#123;<br>        <span class="hljs-type">UserController</span> <span class="hljs-variable">controller</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">UserController</span>();<br>        <span class="hljs-comment">// ... 具体的应用</span><br>    &#125;<br>    <span class="hljs-keyword">static</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserMapper</span> &#123;<br>        <span class="hljs-comment">// CRUD   </span><br>    &#125;<br>    <span class="hljs-keyword">static</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserService</span>&#123;<br>        <span class="hljs-type">UserMapper</span> <span class="hljs-variable">mapper</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">UserMapper</span>();<br>        <span class="hljs-comment">// 业务层代码</span><br>    &#125;<br>    <span class="hljs-keyword">static</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserController</span>&#123;<br>         UserServiceservice = <span class="hljs-keyword">new</span> <span class="hljs-title class_">UserService</span>();<br>        <span class="hljs-comment">// 控制层代码</span><br>    &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>
<p>在上述代码中，假如UserMapper() 发生变更，那么 类UserService就需要进行重构，由于UserController依赖于UserService，故UserController也需要进行重构。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Solution</span>&#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span>&#123;<br>        <span class="hljs-type">UserController</span> <span class="hljs-variable">controller</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">UserController</span>();<br>        <span class="hljs-comment">// ... 具体的应用</span><br>    &#125;<br>    <span class="hljs-keyword">static</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserMapperNew</span> &#123;<br>        <span class="hljs-comment">// CRUD   </span><br>    &#125;<br>    <span class="hljs-keyword">static</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserService</span>&#123;<br>        <span class="hljs-comment">// mapper 发生改变，业务层代码需进行重构</span><br>        <span class="hljs-type">UserMapperNew</span> <span class="hljs-variable">mapper</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">UserMapperNew</span>();<br>        <span class="hljs-comment">// 业务层代码</span><br>    &#125;<br>    <span class="hljs-keyword">static</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserController</span>&#123;<br>        <span class="hljs-comment">// service 发生改变，控制层代码需进行重构</span><br>        UserServiceservice = <span class="hljs-keyword">new</span> <span class="hljs-title class_">UserService</span>();<br>        <span class="hljs-comment">// 控制层代码</span><br>    &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>
<p>综上，在传统MVC架构中，Controller模块依赖于 Service模块，而Service模块依赖于Mapper模块，这样一来结构清晰，但底层模块的变动，会直接影响其他依赖于该模块的高层模块，以下是Spring框架中的代码，高内聚，低耦合：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Solution</span>&#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span>&#123;<br>        <span class="hljs-type">UserController</span> <span class="hljs-variable">controller</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">UserController</span>();<br>        <span class="hljs-comment">// ... 具体的应用</span><br>    &#125;<br>    <span class="hljs-keyword">interface</span> <span class="hljs-title class_">UserMapper</span> &#123;<br>        <span class="hljs-comment">// 接口声明CRUD方法</span><br>    &#125;<br>    <span class="hljs-meta">@Mapper</span><br>    <span class="hljs-keyword">static</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserMapperImpl</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">UserMapper</span>&#123;<br>        <span class="hljs-comment">// 实现类完成CURD具体实现</span><br>    &#125;<br>    <span class="hljs-keyword">interface</span> <span class="hljs-title class_">UserService</span>&#123;<br>        <span class="hljs-comment">// 接口声明业务层方法</span><br>    &#125;<br>    <span class="hljs-meta">@Service</span><br>    <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserServiceImpl</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">UserService</span>&#123;<br>         <span class="hljs-comment">// 实现类完成业务层具体实现   </span><br>    &#125;<br>    <span class="hljs-meta">@Controller</span><br>    <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserController</span>&#123;<br>        <span class="hljs-meta">@Resource</span><br>        <span class="hljs-keyword">private</span> UserService service;	<span class="hljs-comment">// 直接引入Spring IOC 容器中的接口</span><br>        <span class="hljs-comment">// 控制层代码</span><br>    &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>
<p>通过上述代码可以看出，我们可以将原有的强关联弱化，只需要知道接口中定义了什么方法然后去使用即可，而具体的操作由接口的实现类来完成，并由Spring注入接口的实现类，而不是通过之前硬编码的方式去定义。</p>
<h1 id="五、接口隔离原则-ISP"><a href="#五、接口隔离原则-ISP" class="headerlink" title="五、接口隔离原则 ISP"></a>五、接口隔离原则 ISP</h1><hr>
<p>参考资料：<a target="_blank" rel="noopener" href="https://www.runoob.com/note/39073">查看文档</a></p>
<p>接口隔离原则，Interfacce Segregation Principle ，ISP 原则是对接口的细化。</p>
<blockquote>
<p> 客户端不应依赖那些它不需要的接口</p>
</blockquote>
<p>例：在定义接口的时候，一定要注意控制接口的粒度</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 表示设备的接口</span><br><span class="hljs-keyword">interface</span> <span class="hljs-title class_">Device</span>&#123;<br>    String <span class="hljs-title function_">getCpu</span><span class="hljs-params">()</span>;<br>    String <span class="hljs-title function_">getType</span><span class="hljs-params">()</span>;<br>    String <span class="hljs-title function_">getMemory</span><span class="hljs-params">()</span>;<br>&#125;<br><span class="hljs-comment">// 电脑设备</span><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">Computer</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">Device</span>&#123;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getCpu</span><span class="hljs-params">()</span>&#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;i5&quot;</span>;<br>    &#125;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getType</span><span class="hljs-params">()</span>&#123;<br>         <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;电脑&quot;</span>;   <br>    &#125;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getMemory</span><span class="hljs-params">()</span>&#123;<br>         <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;16G&quot;</span>;   <br>    &#125;<br>&#125;<br><span class="hljs-comment">// 电风扇设备</span><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">Fan</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">Device</span>&#123;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getCpu</span><span class="hljs-params">()</span>&#123;<br>         <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;   <br>    &#125;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getType</span><span class="hljs-params">()</span>&#123;<br>         <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;风扇&quot;</span>;   <br>    &#125;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getMemory</span><span class="hljs-params">()</span>&#123;<br>         <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;   <br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>
<pre><code class="hljs">如上述代码，定义的 Device 接口粒度不够细，不能适用于多种设备。故需要再进行划分，如下所示：
</code></pre>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">interface</span> <span class="hljs-title class_">SmartDevice</span>&#123;	<span class="hljs-comment">// 智能设备</span><br>    String <span class="hljs-title function_">getCpu</span><span class="hljs-params">()</span>;<br>    String <span class="hljs-title function_">getType</span><span class="hljs-params">()</span>;<br>    String <span class="hljs-title function_">getMemory</span><span class="hljs-params">()</span>;<br>&#125;<br><span class="hljs-keyword">interface</span> <span class="hljs-title class_">NormalDevice</span>&#123; <span class="hljs-comment">// 普通设备</span><br>    String <span class="hljs-title function_">getType</span><span class="hljs-params">()</span>;<br>&#125;<br><span class="hljs-keyword">class</span> <span class="hljs-title class_">Computer</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">SmartDevice</span>&#123;<br>    ...<br>&#125;<br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">Fan</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">NomarlDevice</span>&#123;<br>    ...   <br>&#125;<br></code></pre></td></tr></table></figure>
<pre><code class="hljs">如此一来，接口更加细化，符合了ISP 的设计原则。
</code></pre>
<h1 id="六、合成复用原则-CRP"><a href="#六、合成复用原则-CRP" class="headerlink" title="六、合成复用原则 CRP"></a>六、合成复用原则 CRP</h1><hr>
<p>合成复用原则，Composite Reuse Principle ，CRP 原则的核心是委派。</p>
<blockquote>
<p>优先使用对象组合，而不是通过继承来达到复用的目的</p>
</blockquote>
<p>如果定义的类C需要用到类A的功能，那么应该优先考虑使用 **合成 **的方式来实现复用。<br><strong>反例：使用继承来实现复用</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">class</span> <span class="hljs-title class_">A</span>&#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">connect</span><span class="hljs-params">()</span>&#123; &#125;    <br>&#125;<br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">C</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">A</span>&#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">test</span><span class="hljs-params">()</span>&#123;<br>         connnect();   <br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>
<p>存在的问题：</p>
<ul>
<li>代码耦合度过高，若类A发生改变，那么类C需要进行重构。</li>
<li>安全性低，类C将会拥有类A所有的方法和变量，不安全。</li>
</ul>
<p>遵循 合成服用原则（CRP）后：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">class</span> <span class="hljs-title class_">A</span>&#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">connect</span><span class="hljs-params">()</span>&#123; &#125;    <br>&#125;<br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">C</span> &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">test</span><span class="hljs-params">(A a)</span>&#123;<br>         a.connnect();   <br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>
<p>或者是将类A定义到类C中：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">class</span> <span class="hljs-title class_">A</span>&#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">connect</span><span class="hljs-params">()</span>&#123; &#125;    <br>&#125;<br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">C</span> &#123;<br>    A a;<br>    <span class="hljs-keyword">public</span> <span class="hljs-title function_">C</span><span class="hljs-params">(A a)</span>&#123;<br>         <span class="hljs-built_in">this</span>.a = a;   <br>    &#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">test</span><span class="hljs-params">()</span>&#123;<br>         a.connnect();   <br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>
<pre><code class="hljs">通过对象之间的组合，降低了类之间的耦合度。
</code></pre>
<h1 id="七、迪米特法则-LOD"><a href="#七、迪米特法则-LOD" class="headerlink" title="七、迪米特法则 LOD"></a>七、迪米特法则 LOD</h1><hr>
<p>迪米特法则，Law of Demeter ，LOD法则又称最少知识原则，是对程序内部数据交互的限制。</p>
<blockquote>
<p>每一个软件单位对其他单位都只有最少的知识，而且局限于那些本单位密切相关的软件单位。</p>
</blockquote>
<p>简单说，一个类 &#x2F; 模块对其他的类 &#x2F; 模块之间交互越少越好。当一个类发生改动，与之相关的类会受到影响，所以交互越少越好，便于降低耦合度。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Main</span>&#123;<br>     <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> IOException&#123;<br>          <span class="hljs-type">Socket</span> <span class="hljs-variable">socket</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Socket</span>(<span class="hljs-string">&quot;localhost&quot;</span>, <span class="hljs-number">8080</span>);<br>          <br>          <span class="hljs-keyword">new</span> <span class="hljs-title class_">Test</span>().test(socket);<br>     &#125;<br>    <span class="hljs-keyword">static</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Test</span>&#123;<br>         <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">test</span><span class="hljs-params">(Socket socket)</span>&#123;<br>             System.out.println(socket.getLocalAddress());<br>         &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>
<pre><code class="hljs">上面这种写法每问题，但是在调用 test方法时，需要传入一个Socket对象，在这里我们的逻辑只是输出socket的IP地址，不符合 LOD 设计原则，可以简化如下：
</code></pre>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Main</span>&#123;<br>     <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> IOException&#123;<br>          <span class="hljs-type">Socket</span> <span class="hljs-variable">socket</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Socket</span>(<span class="hljs-string">&quot;localhost&quot;</span>, <span class="hljs-number">8080</span>);<br>          <span class="hljs-keyword">new</span> <span class="hljs-title class_">Test</span>().test(socket.getLocalAddress());<br>     &#125;<br>    <span class="hljs-keyword">static</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Test</span>&#123;<br>         <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">test</span><span class="hljs-params">(String str)</span>&#123;<br>             System.out.println(str);<br>         &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h1 id="八、总结"><a href="#八、总结" class="headerlink" title="八、总结"></a>八、总结</h1><hr>
<p>通过本次学习，我了解了面向对象的七大设计原则，对我来说，一次性记住是不太现实的，需要在平时编码里时刻注意，比如在完成一段代码后，可以思考一下这个是关于什么设计原则的，或者在看框架源码时，去体会源码设计的方式，从而更深地理解七大设计原则，接下来我将学习23种设计模式，希望通过这样的方式，能提升一定的编码水平。</p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/JavaSE/" class="category-chain-item">JavaSE</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/Java/">#Java</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Java 笔记 面向对象的七大设计原则</div>
      <div>http://example.com/2022/07/11/Java 笔记 面向对象的七大设计原则/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年7月11日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/07/12/ArangoDB%20%E7%AC%94%E8%AE%B02%20AQL%20Java%20API%20_%20AQL%E8%AF%AD%E6%B3%95%20_%20%E4%BD%BF%E7%94%A8Java%E8%BF%9E%E6%8E%A5ArangoDB/" title="ArangoDB 笔记2 AQL Java API _ AQL语法 _ 使用Java连接ArangoDB">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">ArangoDB 笔记2 AQL Java API _ AQL语法 _ 使用Java连接ArangoDB</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/07/10/Quartz%20%E7%AC%94%E8%AE%B02%20%E4%BB%BB%E5%8A%A1%E8%B0%83%E5%BA%A6%E6%A1%86%E6%9E%B6%20_%20%E4%BB%BB%E5%8A%A1%E6%8C%81%E4%B9%85%E5%8C%96%20_%20SpringBoot%20%E6%95%B4%E5%90%88%20Quartz%20%E5%85%A5%E9%97%A8%E6%A1%88%E4%BE%8B%20_%20%E9%80%9A%E8%BF%87web%E6%8E%A7%E5%88%B6%E8%B0%83%E5%BA%A6%E5%99%A8%E7%9A%84%E5%90%AF%E5%8A%A8%E3%80%81%E6%9A%82%E5%81%9C%E3%80%81%E7%BB%A7%E7%BB%AD%E5%92%8C%E5%81%9C%E6%AD%A2/" title="Quartz 笔记2 任务调度框架 _ 任务持久化 _ SpringBoot 整合 Quartz 入门案例 _ 通过web控制调度器的启动、暂停、继续和停止">
                        <span class="hidden-mobile">Quartz 笔记2 任务调度框架 _ 任务持久化 _ SpringBoot 整合 Quartz 入门案例 _ 通过web控制调度器的启动、暂停、继续和停止</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
